import { View } from "@tarojs/components";
import { useRouter, setNavigationBarTitle } from "@tarojs/taro";
import { useDidShow } from "@tarojs/taro";
import { useState } from "react";
import { privacy } from "./components/privacy";
import { user } from "./components/user";
const Protocol = () => {
  const { params } = useRouter();
  const [contents, setContents] = useState<
    { title?: string; childs?: string[] }[]
  >([]);
  useDidShow(() => {
    const data = {
      privacy,
      user,
    }[params?.type || "privacy"];
    setNavigationBarTitle({ title: data?.title || "协议" });
    setContents(data?.childs || []);
  });
  return (
    <View className="p-[30px] text-[#666] text-[28px] leading-[1.6]">
      {contents.map((item, index) => (
        <View key={index} className="mb-[20px]">
          <View className="text-[30px] font-bold mb-[10px]">{item.title}</View>
          {item.childs?.map((child, index) => (
            <View key={index} className="mb-[10px]">
              {child}
            </View>
          ))}
        </View>
      ))}
    </View>
  );
};

export default Protocol;
